<?xml version='1.0' encoding='UTF-8' ?>
<!DOCTYPE composition PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<ui:composition xmlns:h="http://java.sun.com/jsf/html"
                xmlns:f="http://java.sun.com/jsf/core"
                xmlns:ui="http://java.sun.com/jsf/facelets"
                xmlns:p="http://primefaces.org/ui"
                template="./../../template/tagedu.xhtml">

    <ui:define name="title">
        <title><h:outputText value="Peso e Altura - TAG"/></title>
        <h:outputScript name="bigManage.js" library="js"/>
    </ui:define>

    <ui:define name="content">
        <h:outputText styleClass="enrollmentName" value="Peso e Altura"/>
        <h:form id="wahForm" target="_blank">
            <p:messages id="message" autoUpdate="true"/>
            <h:panelGrid id="details" columns="2">
                <h:outputLabel for="wahCampaign" value="Campanha: "/>
                <p:selectOneMenu id="wahCampaign" value="#{weightAndHeightBean.campaign}" converter="campaignC">
                    <f:selectItem value="#{null}" itemLabel="Selecione uma Campanha:"/>
                    <f:selectItems value="#{weightAndHeightBean.campaingList}" var="c" itemLabel="#{c.name}" itemValue="#{c}" />
                    <p:ajax update="wahUnity :fillWH" process="@this"/>
                </p:selectOneMenu>
                
                <h:outputLabel value="Ano: "/>
                <p:spinner value="#{weightAndHeightBean.year}" min="#{weightAndHeightBean.actualYear-1}" max="#{weightAndHeightBean.actualYear}" size="4">
                    <f:validator validatorId="yearV"/>
                    <f:attribute name="minimo" value="#{(weightAndHeightBean.actualYear-1).toString()}"/>
                    <f:attribute name="maximo" value="#{(weightAndHeightBean.actualYear).toString()}"/>
                    <p:ajax update="wahUnity" process="@this"/>  
                </p:spinner>
                
                <h:outputLabel for="wahUnity" value="Turma: "/>
                <p:selectOneMenu id="wahUnity" value="#{weightAndHeightBean.unity}" converter="unityC" disabled="#{weightAndHeightBean.activeUnity()}">
                    <f:selectItem value="#{null}" itemLabel="Selecione uma unidade:"/>
                    <f:selectItems value="#{weightAndHeightBean.unityList}" var="u" itemLabel="#{u.name}" itemValue="#{u}" />
                    <p:ajax update=":fillWH" process="@this" listener="#{weightAndHeightBean.loadTableData()}"/>    
                </p:selectOneMenu>
            </h:panelGrid>
        </h:form>
        <h:form id="fillWH">
            <p:dataTable id="dataTableAlunos" var="Alunos" value="#{weightAndHeightBean.WHList}" emptyMessage="Selecione uma Turma">
                <f:facet name="header">Alunos</f:facet>  

                <p:column headerText="Nome">
                    <h:outputText value="#{Alunos.human.firstName} #{Alunos.human.lastName}"/>
                </p:column>  

                <p:column headerText="Peso">
                    <center>
                        <p:inputText value="#{Alunos.weightAndHeight.weight}" size="10"/>
                    </center>
                </p:column>

                <p:column headerText="Altura">
                    <center>
                        <p:inputText value="#{Alunos.weightAndHeight.height}" size="10"/> 
                    </center>
                </p:column>    

                <f:facet name="footer">  
                    Total de #{weightAndHeightBean.WHList.size()} Alunos.  
                </f:facet>
            </p:dataTable>
            <h:panelGrid columns="2"  cellpadding="10" cellspacing="10">
               <p:commandButton action="#{weightAndHeightBean.save()}"
                                value="Salvar" disabled="#{weightAndHeightBean.activeBottoms()}"/>

                <p:commandButton action="#{weightAndHeightBean.print()}" value="Imprimir" immediate="true" ajax="false"
                        disabled="#{weightAndHeightBean.activeBottoms()}" onclick="this.form.target='_blank'" />
            </h:panelGrid>
        </h:form>
    </ui:define>
</ui:composition>
